package com.nanfang51g3.ckz.ui.money.add;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.InputType;
import android.view.View;
import android.widget.TextView;

import com.nanfang51g3.ckz.R;
import com.nanfang51g3.ckz.application.CkzApplication;
import com.nanfang51g3.ckz.ui.base.IPresenter;
import com.nanfang51g3.ckz.ui.base.Base2Activity;
import com.nanfang51g3.ckz.utils.AppManager;
import com.nanfang51g3.ckz.utils.ButtonUtils;
import com.nanfang51g3.ckz.utils.EasyToast;
import com.nanfang51g3.ckz.utils.KLog;
import com.nanfang51g3.ckz.widget.ClearEditText;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/4/19.
 */
public class AddFinancialInfoActivity extends Base2Activity implements AddFinancialInfoContract.View {
    AddFinancialInfoContract.AddFinancialInfoActionsListener addFinancialInfoActionsListener;
    @Bind(R.id.index_tv_right_title)
    TextView indexTvRightTitle;
    @Bind(R.id.cet_add_financial_info)
    ClearEditText cetAddFinancialInfo;
    int id_title;
    int id_type;
    @Override
    public IPresenter getPresenter() {
        return null;
    }
    @Override
    public int getContentView() {
        return R.layout.add_financial_info;
    }

    @Override
    public boolean isShowLeftIcon() {
        return true;
    }

    @Override
    public boolean isShowRightIcon() {
        return false;
    }

    @Override
    public int setLeftIcon() {
        return R.mipmap.ic_accounting_left;
    }

    @Override
    public int setRightIcon() {
        return 0;
    }

    @Override
    public int showTitle() {
        return id_title;
    }

    @Override
    public void onClickLeft(View v) {
        AppManager.getAppManager().finishActivity(this);
    }

    @Override
    public void onClickRight(View v) {
        EasyToast.showShort(this, "msg");
    }

    @Override
    public void showMessage(String message) {
        EasyToast
                .showShort(this, message);
        cetAddFinancialInfo.setText("");
    }

    @Override
    public void finalView() {
        AppManager.getAppManager().finishActivity(this);

    }

    @Override
    public Context getContext() {
        return this;
    }


    @Override
    public void onIntent() {
        super.onIntent();
        id_title = getIntent().getIntExtra("id_title", 0);
        id_type = getIntent().getIntExtra("id_type", 0);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addFinancialInfoActionsListener = DaggerAddFinancialInfoContractComponent
                .builder()
                .appComponent(CkzApplication.getAppComponent())
                .addFinancialInfoPresenterModule(new AddFinancialInfoPresenterModule(this))
                .build().getAddFinancialInfoPresenter();
        KLog.i("TAG", addFinancialInfoActionsListener == null ? "addFinancialInfoActionsListener==null" : "addFinancialInfoActionsListener!=null");
        ButterKnife.bind(this);
        indexTvRightTitle.setVisibility(View.VISIBLE);
        indexTvRightTitle.setText(R.string.str_save);
        switch (id_title) {
            case R.string.str_financial_name:
                cetAddFinancialInfo.setInputType(InputType.TYPE_CLASS_TEXT);
                cetAddFinancialInfo.setHint(R.string.str_add_01);
                break;
            case R.string.str_financial_bank:
                cetAddFinancialInfo.setInputType(InputType.TYPE_CLASS_TEXT);
                cetAddFinancialInfo.setHint(R.string.str_add_02);
                break;
            case R.string.str_financial_card:
                cetAddFinancialInfo.setInputType(InputType.TYPE_CLASS_NUMBER);
                cetAddFinancialInfo.setHint(R.string.str_add_03);
                break;
            case R.string.str_financial_ali_pay:
                cetAddFinancialInfo.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                cetAddFinancialInfo.setHint(R.string.str_add_04);
                break;
        }

    }

    @OnClick(R.id.index_tv_right_title)
    public void index_tv_right_title(View view) {
        String content = cetAddFinancialInfo.getText().toString().trim();
        if (!ButtonUtils.isFastDoubleClick(R.id.index_tv_right_title)) {
            switch (id_title) {
                case R.string.str_financial_name:
                    /**
                     * @see AddFinancialInfoPresenter#addRelName(String)
                     */
                    addFinancialInfoActionsListener.addRelName(content);

                    break;
                case R.string.str_financial_bank:
                    /**
                     * @see AddFinancialInfoPresenter#addBankName(String)
                     */
                    addFinancialInfoActionsListener.addBankName(content);

                    break;
                case R.string.str_financial_card:
                    /**
                     * @see AddFinancialInfoPresenter#addBankCard(String)
                     */
                    addFinancialInfoActionsListener.addBankCard(content);

                    break;
                case R.string.str_financial_ali_pay:
                    /**
                     * @see AddFinancialInfoPresenter#addAliPay(String)
                     */
                    addFinancialInfoActionsListener.addAliPay(content);

                    break;
            }
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        ButterKnife.unbind(this);//解除绑定，官方文档只对fragment做了解绑

    }
}
